﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VerdePimienta2._0
{
    public partial class basura : Form
    {
        public basura()
        {
            InitializeComponent();
        }

        private int GenerarCodigoCLiente()
        {
            int codigo = 0;
            //string consulta = "Select count(*) from Clientes";

            //SqlConnection conexion = new SqlConnection(constring);
            //conexion.Open();

            //SqlCommand cmd = conexion.CreateCommand();
            //cmd.CommandText = consulta;

            //codigo = (int)cmd.ExecuteScalar() + 1;
            //cmd.Dispose();

            //conexion.Close();

            return codigo;
        }
        private void btnBuscarCliente_Click(object sender, EventArgs e)
        {
            //SqlConnection c = new SqlConnection(constring);
            //c.Open();

            //SqlDataAdapter daB = new SqlDataAdapter("Select * From Clientes where (Nombre = @parametro) or (Telefono = @parametro) or (Movil = @parametro)", c);
            //daB.SelectCommand.Parameters.AddWithValue("@parametro", txtCampoBusqueda.Text);

            //DataSet dsB = new DataSet("Clientes");
            //daB.FillSchema(dsB, SchemaType.Source, "Clientes");
            //daB.Fill(dsB, "Clientes");

            //DataTable tblB;
            //tblB = dsB.Tables["Clientes"];

            //c.Close();
            //clientesVentaDataGridView.DataSource = dsB.Tables["Clientes"].DefaultView;
        }
        //                //Asociar CLIENTE a la VENTA
        //                if (txtNombreCliente.Text != "")
        //                {
        //                    drVentaTickets["IdCliente"] = lblId.Text;
        //                    if (txtSinPagar.Text != "")
        //                    {
        //                        string strSQL = "UPDATE Clientes SET" +
        //                         " Deuda = '" + txtSinPagar.Text +
        //                         "' WHERE Id = " + lblId.Text;

        //                        SqlConnection conexionClientes = new SqlConnection(constring);
        //                        conexionClientes.Open();
        //                        SqlCommand cmSQL = new SqlCommand(strSQL, conexionClientes);
        //                        cmSQL.ExecuteNonQuery();
        //                        conexionClientes.Close();
        //                    }
        //                }
        //                else
        //                {
        //                    drVentaTickets["IdCliente"] = 0;
        //                }

        private void clientesVentaDataGridView_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewRow row = clientesVentaDataGridView.CurrentRow;

            if (row != null)
            {
                lblIdClienteExistente.Text = row.Cells[0].Value.ToString();
                txtNombreClienteExistente.Text = row.Cells[1].Value.ToString();
                txtTlfClienteExistente.Text = row.Cells[3].Value.ToString();
                txtboxMovilClienteExistente.Text = row.Cells[4].Value.ToString();

            }
        }

        private void btnNuevoCliente_Click(object sender, EventArgs e)
        {
            panelClienteExistente.Visible = false;
            panelClienteNuevo.Visible = true;

            lblIdClienteNuevo.Text = GenerarCodigoCLiente().ToString();
        }
    }

}
